import PopupMenu from "./PopupMenu";
import BitmapText from "../BitmapText";
import GameConst from "../GameConst";
import Utils from "../utils";

export default class TargetMenu extends PopupMenu {
    constructor() {
        super('target_panel');
         
        this.targetSprites = [];
        this.showDelay = 150;
        var t = this.sprite;
        var continueT = Utils.createSprite('menu/tipcontinue.png');
        t.addChild(continueT);
        this.continueText = continueT;
        for (var i = 2; i >= 0; --i) {
            var targetIco = new Laya.Sprite();
            targetIco.y = 300 + i * 30 - 210;
            targetIco.rotation = i * -30;
            this.baseSprite.addChild(targetIco);
            this.targetSprites.push(targetIco)
        }
        var text = new BitmapText(" ", "menu/");
        text.letterSpacing = 8.5;
        text.spaceWidth = 25;
        this.targetTexts = text;
        this.baseSprite.addChild(text);
        this.onResize()
    }

    onResize() {
        super.onResize();
        this.continueText.y = GameConst.ACTUAL_H - this.sprite.y;
    };
    show() {
        super.show();
        var txtList = GameConst.level.target.getText();
        var n = GameConst.SCREEN_W - 200;
        var text = txtList[0]+txtList[1];
        this.targetTexts.text = text;
        var bd = this.targetTexts.getBounds();
        this.targetTexts.y = 150;
        this.targetTexts.x = GameConst.SCREEN_W/2-bd.width/2;
        for (var r = 0; r < 3; ++r) {
            var dySp = this.targetSprites[r];
            var name = txtList[2];
            dySp.loadImage('game/'+name+".png");
            dySp.scaleX = dySp.scaleY = name == "star" ? 0.66 : 1;
            dySp.x = n + 15 - (r == 2 ? 0 : r == 1 ? 25 : 19) + 45 + 10;
            dySp.pivotX = dySp.getBounds().width / 2;
            dySp.pivotY = dySp.getBounds().height / 2
        }
        this.continueText.visible = true;
        this.continueText.x = GameConst.SCREEN_W / 2 - this.continueText.getBounds().width / 2;
    };


    hide() {
        super.hide();
        this.continueText.visible = false;
    };

    onUp(t, n) {
        if(this.continueText.visible){
            this.hide();
            //GameConst.menuManager.closeCurrent();
            if (GameConst.level.isPaused){
                GameConst.level.unpause()
            }
        }
    };
}